package jade.proto;

//#J2ME_EXCLUDE_FILE

import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;

public class TestSS extends Agent {

	private MessageTemplate template = MessageTemplate.MatchPerformative(ACLMessage.CFP);
	
	protected void setup() {
		addBehaviour(new SSResponderDispatcher(this, template) {

			@Override
			protected Behaviour createResponder(ACLMessage cfp) {
				return new SSContractNetResponder(myAgent, cfp) {
					
					@Override
					public ACLMessage handleCfp(ACLMessage cfp) {
						System.out.println("CFP Received");
						ACLMessage reply = cfp.createReply();
						reply.setPerformative(ACLMessage.PROPOSE);
						return reply;
					}
					
					@Override
					public ACLMessage handleAcceptProposal(ACLMessage cfp, ACLMessage propose, ACLMessage accept) {
						System.out.println("ACCEPT_PROPOSAL Received");
						ACLMessage inform = accept.createReply();
						inform.setPerformative(ACLMessage.INFORM);
						return inform;
					}
					
					@Override
					public void handleRejectProposal(ACLMessage cfp, ACLMessage propose, ACLMessage reject) {
						System.out.println("REJECT_PROPOSAL Received");
					}
				};
			}
			
		});
	}
}
